package com.controller;

import com.mapper.GoodsMapper;
import com.pojo.*;
import com.service.*;
import com.util.VeDate;
import com.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

//定义为控制器
@Controller
// 设置路径
@RequestMapping("/index")
public class IndexController extends BaseController {
    @Autowired
    @Resource
    private UsersService usersService;
    @Autowired
    @Resource
    private ArticleService articleService;
    @Autowired
    @Resource
    private CateService cateService;
    @Autowired
    @Resource
    private GoodsService goodsService;
    @Autowired
    @Resource
    private CartService cartService;
    @Autowired
    @Resource
    private OrdersService ordersService;
    @Autowired
    @Resource
    private ItemsService itemsService;
    @Autowired
    @Resource
    private TopicService topicService;
    @Autowired
    @Resource
    private EmployService employService;
    @Autowired
    @Resource
    private AllotService allotService;

    @GetMapping("/plogin")
    @ResponseBody
    public Result plogin(HttpSession httpSession, HttpServletRequest request) {

        String codes = request.getParameter("codes");
        String pcode = (String) httpSession.getAttribute("pcode");
        String number = request.getParameter("memPhone");
        Users user=usersService.findByNumber(number);
        if (user != null) {
            if (number != null && number.equals(user.getContact())){
                if (codes.equals(pcode)) {
                    request.getSession().setAttribute("userid", user.getUsersid());
                    request.getSession().setAttribute("username", user.getUsername());
                    request.getSession().setAttribute("users", user);
                    return new Result("200","登录成功",null);
                }
                return new Result("404","验证码不正确",null);
            }
            return new Result("500","号码不正确",null);
        }
        return new Result("403","用户不存在",null);
    }




    @GetMapping("home")
    public String home(){
        return "users/index";
    }
    // 公共方法 提供公共查询数据
    private void front() {
        this.getRequest().setAttribute("title", "家政服务平台管理系统");
        List<Cate> cateList = this.cateService.getAllCate();
        this.getRequest().setAttribute("cateList", cateList);
        List<Goods> hotList = this.goodsService.getGoodsByHot();
        this.getRequest().setAttribute("hotList", hotList);
    }
    // 首页显示
    @RequestMapping("/index")
    public String index() {
        this.front();
        List<Cate> cateList = this.cateService.getCateFront();
        List<Cate> frontList = new ArrayList<Cate>();
        for (Cate cate : cateList) {
            List<Goods> goodsList = this.goodsService.getGoodsByCate(cate.getCateid());
            cate.setGoodsList(goodsList);
            frontList.add(cate);
        }
        this.getRequest().setAttribute("frontList", frontList);
        return "users/index";
    }
    // 公告
    @RequestMapping("/article")
    public String article(String number) {
        this.front();
        List<Article> articleList = new ArrayList<Article>();
        List<Article> tempList = this.articleService.getAllArticle();
        int pageNumber = tempList.size();
        int maxPage = pageNumber;
        if (maxPage % 10 == 0) {
            maxPage = maxPage / 10;
        } else {
            maxPage = maxPage / 10 + 1;
        }
        if (number == null) {
            number = "0";
        }
        int start = Integer.parseInt(number) * 10;
        int over = (Integer.parseInt(number) + 1) * 10;
        int count = pageNumber - over;
        if (count <= 0) {
            over = pageNumber;
        }
        for (int i = start; i < over; i++) {
            Article x = tempList.get(i);
            articleList.add(x);
        }
        String html = "";
        StringBuffer buffer = new StringBuffer();
        buffer.append("&nbsp;&nbsp;共为");
        buffer.append(maxPage);
        buffer.append("页&nbsp; 共有");
        buffer.append(pageNumber);
        buffer.append("条&nbsp; 当前为第");
        buffer.append((Integer.parseInt(number) + 1));
        buffer.append("页 &nbsp;");
        if ((Integer.parseInt(number) + 1) == 1) {
            buffer.append("首页");
        } else {
            buffer.append("<a href=\"index/article?number=0\">首页</a>");
        }
        buffer.append("&nbsp;&nbsp;");
        if ((Integer.parseInt(number) + 1) == 1) {
            buffer.append("上一页");
        } else {
            buffer.append("<a href=\"index/article?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
        }
        buffer.append("&nbsp;&nbsp;");
        if (maxPage <= (Integer.parseInt(number) + 1)) {
            buffer.append("下一页");
        } else {
            buffer.append("<a href=\"index/article?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
        }
        buffer.append("&nbsp;&nbsp;");
        if (maxPage <= (Integer.parseInt(number) + 1)) {
            buffer.append("尾页");
        } else {
            buffer.append("<a href=\"index/article?number=" + (maxPage - 1) + "\">尾页</a>");
        }
        html = buffer.toString();
        this.getRequest().setAttribute("html", html);
        this.getRequest().setAttribute("articleList", articleList);
        return "users/article";
    }

    // 阅读公告
    @RequestMapping("/read")
    public String read(String id) {
        this.front();
        Article article = this.articleService.getArticleById(id);
        article.setHits("" + (Integer.parseInt(article.getHits()) + 1));
        this.articleService.updateArticle(article);
        this.getRequest().setAttribute("article", article);
        return "users/read";
    }

    // 准备登录
    @RequestMapping("/preLogin")
    public String prelogin() {
        this.front();
        return "users/login";
    }

    // 用户登录
    @RequestMapping("/login")
    public String login() {
        this.front();
        String username = this.getRequest().getParameter("username");
        String password = this.getRequest().getParameter("password");
        Users u = new Users();
        u.setUsername(username);
        List<Users> usersList = this.usersService.getUsersByCond(u);
        if (usersList.size() == 0) {
            this.getSession().setAttribute("message", "用户名不存在");
            return "redirect:/index/preLogin";
        } else {
            Users users = usersList.get(0);
            if (password.equals(users.getPassword())) {
                this.getSession().setAttribute("userid", users.getUsersid());
                this.getSession().setAttribute("username", users.getUsername());
                this.getSession().setAttribute("users", users);
                return "redirect:/index/index";
            } else {
                this.getSession().setAttribute("message", "密码错误");
                return "redirect:/index/preLogin";
            }
        }
    }

    // 准备注册
    @RequestMapping("/preReg")
    public String preReg() {
        this.front();
        return "users/register";
    }

    // 用户注册
    @RequestMapping("/register")
    public String register(Users users) {
        this.front();
        Users u = new Users();
        u.setUsername(users.getUsername());
        List<Users> usersList = this.usersService.getUsersByCond(u);
        if (usersList.size() == 0) {
            users.setRegdate(VeDate.getStringDateShort());
            this.usersService.insertUsers(users);
        } else {
            this.getSession().setAttribute("message", "用户名已存在");
            return "redirect:/index/preReg";
        }

        return "users/login";
    }

    // 退出登录
    @RequestMapping("/exit")
    public String exit() {
        this.front();
        this.getSession().removeAttribute("userid");
        this.getSession().removeAttribute("username");
        this.getSession().removeAttribute("users");
        return "index";
    }

    // 准备修改密码
    @RequestMapping("/prePwd")
    public String prePwd() {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        return "users/editpwd";
    }

    // 修改密码
    @RequestMapping("/editpwd")
    public String editpwd() {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        String userid = (String) this.getSession().getAttribute("userid");
        String password = this.getRequest().getParameter("password");
        String repassword = this.getRequest().getParameter("repassword");
        Users users = this.usersService.getUsersById(userid);
        if (password.equals(users.getPassword())) {
            users.setPassword(repassword);
            this.usersService.updateUsers(users);
        } else {
            this.getSession().setAttribute("message", "旧密码错误");
            return "redirect:/index/prePwd";
        }
        return "redirect:/index/prePwd";
    }
   //用户个人中心
    @RequestMapping("/usercenter")
    public String usercenter() {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        return "users/usercenter";
    }

    @RequestMapping("/userinfo")
    public String userinfo() {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        String userid = (String) this.getSession().getAttribute("userid");
        this.getSession().setAttribute("users", this.usersService.getUsersById(userid));
        return "users/userinfo";
    }



    @RequestMapping("/personal")
    public String personal(Users users) {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        this.usersService.updateUsers(users);
        return "redirect:/index/userinfo";
    }


    // 添加产品到购物车
    @RequestMapping("/addcart")
    public String addcart() {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        String userid = (String) this.getSession().getAttribute("userid");
        Users users=usersService.getUsersById(userid);
        Goods goods=goodsService.find(getRequest().getParameter("goodsid"));
        Cart cart = new Cart();
        cart.setAddtime(VeDate.getStringDateShort());
        cart.setGoodsid(getRequest().getParameter("goodsid"));
        cart.setPrice(getRequest().getParameter("price"));
        cart.setUsersid(userid);
        cart.setImage(goods.getImage());
        cart.setUsername(goods.getGoodsname());
        cart.setUsername(users.getUsername());
        this.cartService.insertCart(cart);

        return "redirect:/index/cart";
    }

    // 查看购物车
    @RequestMapping("/cart")
    public String cart() {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        String userid = (String) this.getSession().getAttribute("userid");
        Cart cart = new Cart();
        cart.setUsersid(userid);
        List<Cart> cartList = this.cartService.getCartByCond(cart);
        this.getRequest().setAttribute("cartList", cartList);
        return "users/cart";
    }

    // 删除购物车中的产品
    @RequestMapping("/deletecart")
    public String deletecart(String id) {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        this.cartService.deleteCart(id);
        return "redirect:/index/cart";
    }

    // 准备结算
    @RequestMapping("/preCheckout")
    public String preCheckout() {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        String userid = (String) this.getSession().getAttribute("userid");
        Cart cart = new Cart();
        cart.setUsersid(userid);
        List<Cart> cartList = this.cartService.getCartByCond(cart);
        if (cartList.size() == 0) {
            this.getRequest().setAttribute("message", "请选购商品");
            return "redirect:/index/cart";
        }
        return "users/checkout";
    }

    // 结算
    @RequestMapping("/checkout")
    public String checkout() {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        String userid = (String) this.getSession().getAttribute("userid");
        Cart cart1 = new Cart();
        cart1.setUsersid(userid);
        List<Cart> cartList = this.cartService.getCartByCond(cart1);
        if (cartList.size() == 0) {
            this.getRequest().setAttribute("message", "请选购商品");
            return "redirect:/index/cart";
        } else {
            // 获取一个1000-9999的随机数 防止同时提交
            String ordercode = "PD" + VeDate.getStringDatex();
            double total = 0;
            for (Cart cart : cartList) {
                Items details = new Items();
                details.setItemsid(VeDate.getStringDatex() + (Math.random() * 9 + 1) * 1000);
                details.setGoodsid(cart.getGoodsid());
                details.setOrdercode(ordercode);
                details.setPrice(cart.getPrice());
                Goods goods = this.goodsService.getGoodsById(cart.getGoodsid());
                details.setGoodsname(goods.getGoodsname());
                this.itemsService.insertItems(details);
                goods.setSellnum("" + (Integer.parseInt(goods.getSellnum()) + 1));
                this.goodsService.updateGoods(goods);
                total += Double.parseDouble(cart.getPrice());
                this.cartService.deleteCart(cart.getCartid());
            }
            String workdate = this.getRequest().getParameter("workdate");
            String enddate = this.getRequest().getParameter("enddate");
            String worktime = this.getRequest().getParameter("worktime");
            long days = VeDate.getDays(enddate, workdate) + 1;
            Orders orders = new Orders();
            orders.setAddress(getRequest().getParameter("address"));
            orders.setAddtime(VeDate.getStringDateShort());
            orders.setContact(getRequest().getParameter("contact"));
            orders.setOrdercode(ordercode);
            orders.setStatus("已付款");
            orders.setTotal("" + VeDate.getDouble(total));
            orders.setUsersid(userid);
            orders.setEnddate(enddate);
            orders.setWorkdate(workdate);
            orders.setWorktime(worktime);
            this.ordersService.insertOrders(orders);
        }
        return "redirect:/index/showOrders";
    }

    // 查看订购
    @RequestMapping("/showOrders")
    public String showOrders(String number) {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        String userid = (String) this.getSession().getAttribute("userid");
        Orders orders = new Orders();
        orders.setUsersid(userid);
        List<Orders> ordersList = new ArrayList<Orders>();
        List<Orders> tempList = this.ordersService.getOrdersByCond(orders);
        int pageNumber = tempList.size();
        int maxPage = pageNumber;
        if (maxPage % 10 == 0) {
            maxPage = maxPage / 10;
        } else {
            maxPage = maxPage / 10 + 1;
        }
        if (number == null) {
            number = "0";
        }
        int start = Integer.parseInt(number) * 10;
        int over = (Integer.parseInt(number) + 1) * 10;
        int count = pageNumber - over;
        if (count <= 0) {
            over = pageNumber;
        }
        for (int i = start; i < over; i++) {
            Orders o = tempList.get(i);
            ordersList.add(o);
        }
        String html = "";
        StringBuffer buffer = new StringBuffer();
        buffer.append("&nbsp;&nbsp;共为");
        buffer.append(maxPage);
        buffer.append("页&nbsp; 共有");
        buffer.append(pageNumber);
        buffer.append("条&nbsp; 当前为第");
        buffer.append((Integer.parseInt(number) + 1));
        buffer.append("页 &nbsp;");
        if ((Integer.parseInt(number) + 1) == 1) {
            buffer.append("首页");
        } else {
            buffer.append("<a href=\"index/showOrders?number=0\">首页</a>");
        }
        buffer.append("&nbsp;&nbsp;");
        if ((Integer.parseInt(number) + 1) == 1) {
            buffer.append("上一页");
        } else {
            buffer.append("<a href=\"index/showOrders?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
        }
        buffer.append("&nbsp;&nbsp;");
        if (maxPage <= (Integer.parseInt(number) + 1)) {
            buffer.append("下一页");
        } else {
            buffer.append("<a href=\"index/showOrders?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
        }
        buffer.append("&nbsp;&nbsp;");
        if (maxPage <= (Integer.parseInt(number) + 1)) {
            buffer.append("尾页");
        } else {
            buffer.append("<a href=\"index/showOrders?number=" + (maxPage - 1) + "\">尾页</a>");
        }
        html = buffer.toString();
        this.getRequest().setAttribute("html", html);
        this.getRequest().setAttribute("ordersList", ordersList);
        return "users/orderlist";
    }

    // 准备付款
    @RequestMapping("/prePay")
    public String prePay(String id) {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        this.getRequest().setAttribute("id", id);
        Orders order=ordersService.getOrdersById(id);
        this.getRequest().setAttribute("order",order);
        System.out.println(order);
        System.out.println(order.getTotal()+"==========");
        return "users/pay";
    }

    // 付款
    @RequestMapping("/pay")
    public String pay(String id) {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        String oid=getRequest().getParameter("id");
        Orders orders = this.ordersService.getOrdersById(oid);
        orders.setStatus("已付款");
        this.ordersService.updateOrders(orders);
        return "redirect:/index/showOrders";
    }
    // 确认收货
    @RequestMapping("/preTopic")
    public String preTopic(String id) {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        Orders orders = this.ordersService.getOrdersById(this.getRequest().getParameter("id"));
        Items items = new Items();
        items.setOrdercode(orders.getOrdercode());
        List<Items> itemsList = this.itemsService.getItemsByCond(items);
        this.getRequest().setAttribute("detailsList", itemsList);
        this.getRequest().setAttribute("orders", orders);
        return "users/addTopic";
    }

    // 取消订单
    @RequestMapping("/addTopic")
    public String addTopic() {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        Orders orders = this.ordersService.getOrdersById(this.getRequest().getParameter("id"));
        orders.setStatus("已评价");
        this.ordersService.updateOrders(orders);
        Items items = new Items();
        items.setOrdercode(orders.getOrdercode());
        List<Items> itemsList = this.itemsService.getItemsByCond(items);
        String userid = (String) this.getSession().getAttribute("userid");
        for (int i = 0; i < itemsList.size(); i++) {
            Items x = itemsList.get(i);
            Topic topic = new Topic();
            topic.setTopicid(UUID.randomUUID().toString());
            topic.setGoodsid(x.getGoodsid());
            topic.setContents(this.getRequest().getParameter("contents_" + i));
            topic.setNum(this.getRequest().getParameter("num_" + i));
            topic.setOrdersid(orders.getOrdersid());
            topic.setUsersid(userid);
            topic.setAddtime(VeDate.getStringDate());
            topic.setStatus("未回复");
            this.topicService.insertTopic(topic);
        }
        return "redirect:/index/showOrders";
    }

    @RequestMapping("/myTopic")
    public String myTopic() {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        String userid = (String) this.getSession().getAttribute("userid");
        Topic topic = new Topic();
        topic.setUsersid(userid);
        List<Topic> topicList = this.topicService.getTopicByCond(topic);
        this.getRequest().setAttribute("topicList", topicList);
        return "users/myTopic";
    }

    // 订单明细
    @RequestMapping("/orderdetail")
    public String orderdetail(String id) {
        this.front();
        if (this.getSession().getAttribute("userid") == null) {
            return "redirect:/index/preLogin";
        }
        Items details = new Items();
        details.setOrdercode(id);
        List<Items> detailsList = this.itemsService.getItemsByCond(details);
        this.getRequest().setAttribute("detailsList", detailsList);
        return "users/orderdetail";
    }

    // 按分类查询
    @RequestMapping("/cate")
    public String cate(String id, String number) {
        this.front();
        Goods goods = new Goods();
        goods.setCateid(id);
        List<Goods> goodsList = new ArrayList<Goods>();
        List<Goods> tempList = this.goodsService.getGoodsByCond(goods);
        int pageNumber = tempList.size();
        int maxPage = pageNumber;
        if (maxPage % 4 == 0) {
            maxPage = maxPage / 4;
        } else {
            maxPage = maxPage / 4 + 1;
        }
        if (number == null) {
            number = "0";
        }
        int start = Integer.parseInt(number) * 4;
        int over = (Integer.parseInt(number) + 1) * 4;
        int count = pageNumber - over;
        if (count <= 0) {
            over = pageNumber;
        }
        for (int i = start; i < over; i++) {
            Goods x = tempList.get(i);
            goodsList.add(x);
        }
        String html = "";
        StringBuffer buffer = new StringBuffer();
        buffer.append("&nbsp;&nbsp;共为");
        buffer.append(maxPage);
        buffer.append("页&nbsp; 共有");
        buffer.append(pageNumber);
        buffer.append("条&nbsp; 当前为第");
        buffer.append((Integer.parseInt(number) + 1));
        buffer.append("页 &nbsp;");
        if ((Integer.parseInt(number) + 1) == 1) {
            buffer.append("首页");
        } else {
            buffer.append("<a href=\"index/cate?number=0&id=\" + id+ \"\">首页</a>");
        }
        buffer.append("&nbsp;&nbsp;");
        if ((Integer.parseInt(number) + 1) == 1) {
            buffer.append("上一页");
        } else {
            buffer.append("<a href=\"index/cate?number=" + (Integer.parseInt(number) - 1) + "&id=\" + id+ \"\">上一页</a>");
        }
        buffer.append("&nbsp;&nbsp;");
        if (maxPage <= (Integer.parseInt(number) + 1)) {
            buffer.append("下一页");
        } else {
            buffer.append("<a href=\"index/cate?number=" + (Integer.parseInt(number) + 1) + "&id=\" + id+ \"\">下一页</a>");
        }
        buffer.append("&nbsp;&nbsp;");
        if (maxPage <= (Integer.parseInt(number) + 1)) {
            buffer.append("尾页");
        } else {
            buffer.append("<a href=\"index/cate?number=" + (maxPage - 1) + "&id=\" + id+ \"\">尾页</a>");
        }
        html = buffer.toString();
        this.getRequest().setAttribute("html", html);
        this.getRequest().setAttribute("goodsList", goodsList);
        return "users/list";
    }

    // 全部产品
    @RequestMapping("/all")
    public String all(String number) {
        int pageSize = 10;
        this.front();
        List<Goods> goodsList = new ArrayList<Goods>();
        List<Goods> tempList = this.goodsService.getAllGoods();
        int pageNumber = tempList.size();
        int maxPage = pageNumber;
        if (maxPage % pageSize == 0) {
            maxPage = maxPage/pageSize;
        } else {
            maxPage = maxPage/pageSize + 1;
        }
        if (number == null) {
            number = "0";
        }
        int start = Integer.parseInt(number) * pageSize;
        int over = (Integer.parseInt(number) + 1) * pageSize;
        int count = pageNumber - over;
        if (count <= 0) {
            over = pageNumber;
        }
        for (int i = start; i < over; i++) {
            Goods x = tempList.get(i);
            goodsList.add(x);
        }
        String html = "";
        StringBuffer buffer = new StringBuffer();
        buffer.append("&nbsp;&nbsp;共为");
        buffer.append(maxPage);
        buffer.append("页&nbsp; 共有");
        buffer.append(pageNumber);
        buffer.append("条&nbsp; 当前为第");
        buffer.append((Integer.parseInt(number) + 1));
        buffer.append("页 &nbsp;");
        if ((Integer.parseInt(number) + 1) == 1) {
            buffer.append("首页");
        } else {
            buffer.append("<a href=\"index/all?number=0\">首页</a>");
        }
        buffer.append("&nbsp;&nbsp;");
        if ((Integer.parseInt(number) + 1) == 1) {
            buffer.append("上一页");
        } else {
            buffer.append("<a href=\"index/all?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
        }
        buffer.append("&nbsp;&nbsp;");
        if (maxPage <= (Integer.parseInt(number) + 1)) {
            buffer.append("下一页");
        } else {
            buffer.append("<a href=\"index/all?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
        }
        buffer.append("&nbsp;&nbsp;");
        if (maxPage <= (Integer.parseInt(number) + 1)) {
            buffer.append("尾页");
        } else {
            buffer.append("<a href=\"index/all?number=" + (maxPage - 1) + "\">尾页</a>");
        }
        html = buffer.toString();
        this.getRequest().setAttribute("html", html);
        this.getRequest().setAttribute("goodsList", goodsList);
        return "users/list";
    }

    // 查询商品
    @RequestMapping("/query")
    public String query(String name) {
        this.front();
        Goods goods = new Goods();
        goods.setGoodsname(name);
        List<Goods> goodsList = this.goodsService.getGoodsByLike(goods);
        this.getRequest().setAttribute("goodsList", goodsList);
        return "users/list";
    }

    // 商品详情
    @RequestMapping("/detail")
    public String detail(String id) {
        this.front();
        Goods goods = this.goodsService.getGoodsById(id);
        goods.setHits("" + (Integer.parseInt(goods.getHits()) + 1));
        this.goodsService.updateGoods(goods);
        this.getRequest().setAttribute("goods", goods);
        Topic topic = new Topic();
        topic.setGoodsid(id);
        List<Topic> topicList = this.topicService.getTopicByCond(topic);
        this.getRequest().setAttribute("topicList", topicList);
        this.getRequest().setAttribute("tnum", topicList.size());
        return "users/detail";
    }
}
